//-------------------------------------------------------------------------------------------------
// <copyright file="SA1501.cs" company="OfficeClip LLC">
// Copyright (c) OfficeClip LLC.  All rights reserved.
// </copyright>
//-------------------------------------------------------------------------------------------------

namespace OfficeClip.OpenSource.StyleFix.Drivers
{
    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Text.RegularExpressions;

    public class SA1501
    {
        public static string Run(string input)
        {
            string[] tokens = input.Split(new[] { '{', '}' });

            // First get the first non-white space on the line
            Regex reg = new Regex(@"^(\W+)");
            Match m = reg.Match(tokens[0]);
            string prefix = m.Groups[0].Value;
            string outputLine = string.Empty;
            if (tokens[0].Trim().StartsWith("if"))
            {
                outputLine += tokens[0] + System.Environment.NewLine;
            }

            outputLine += prefix + "{" + System.Environment.NewLine + prefix + "    " + tokens[1];

            // If the right braces is present then put it in the next line
            if (input.TrimEnd().EndsWith("}"))
            {
                outputLine += System.Environment.NewLine + prefix + "}";
            }

            return outputLine;
        }
    }
}
